package com.bfly.mall.product.controller;

import com.bfly.common.ResponseUtil;
import com.bfly.core.base.controller.BaseController;
import com.bfly.core.enums.SysError;
import com.bfly.core.exception.ServiceResponseException;
import com.bfly.core.base.entity.ResponseData;
import com.bfly.core.security.PermissionCheck;
import com.bfly.mall.product.entity.ProductTxt;
import com.bfly.mall.product.dto.ProductTxtDTO;
import com.bfly.mall.product.service.IProductTxtService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 产品详情
 *
 * @author 长沙商脉科技有限公司
 * @date 2020/9/21 19:42
 */
@RestController
@RequestMapping(value = "/manage/product/txt")
public class ProductTxtController extends BaseController {

    @Autowired
    private IProductTxtService txtService;

    /**
     * 获得产品详情信息
     *
     * @author 长沙商脉科技有限公司
     * @date 2020/9/23 19:52
     */
    @GetMapping(value = "/detail")
    @PermissionCheck(required = false)
    public void getProductTxt(HttpServletResponse response, @RequestParam(value = "productId", defaultValue = "0") int productId) {
        ProductTxt txt = txtService.getTxt(productId);
        if(txt==null){
            throw new ServiceResponseException(SysError.PARAM_ERROR,"不存在的产品信息!");
        }
        ProductTxtDTO dto=new ProductTxtDTO();
        BeanUtils.copyProperties(txt,dto);
        ResponseUtil.writeJson(response, ResponseData.getSuccess(dto));
    }
}